package com.nuc.thread.synchronizedTest;

import lombok.extern.slf4j.Slf4j;

/**
 * @Description wait.notify.notifyAll测试
 * @Author 诗酒趁年华
 * @Version V1.0.0
 * @Date 2021/5/9
 */
@Slf4j
public class TestWait {
    static Object lock = new Object();
    public static void main(String[] args) throws InterruptedException {
        new Thread(()->{
            synchronized (lock){
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                log.debug("t1线程执行其他代码");
            }
        },"t1").start();

        new Thread(()->{
            synchronized (lock){
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                log.debug("t2线程执行其他代码");
            }
        },"t2").start();

        Thread.sleep(2000);
        log.debug("主线程唤醒其他线程");
        synchronized (lock){
//            lock.notify();//唤醒任意一个线程
            lock.notifyAll();
        }


    }
}
